﻿/// <reference path="jquery-1.5.1-vsdoc.js" />
$(document).ready(function () {
    $('#Eq_MadeDate').datepicker();

    $('form').validate({
        rules: {
            Eq_Name: 'required',
            Eq_Type: 'required',
            Eq_OwnerCompanyId: { required: '#IsLocal:checked' },
            Eq_Owner: { required: '#IsLocal:unchecked' },
            Eq_OwnerInCharge: { required: '#IsLocal:unchecked' },
            Eq_OwnerPhone: { required: '#IsLocal:unchecked' },
            Eq_SpecCertNo: 'required',
            Eq_CertNo: 'required',
            Eq_ProducerCompanyId: { required: '#IsLocal:checked' },
            Eq_Producer: { required: '#IsLocal:unchecked' },
            Eq_MadeDate: 'required',
            LimitedMonth : 'required'
        },
        messages: {
            Eq_Name: '设备名称不能为空',
            Eq_Type: '设备型号不能为空',
            Eq_OwnerCompanyId: '产权单位不能为空',
            Eq_Owner: '产权单位不能为空',
            Eq_OwnerInCharge: '负责人不能为空',
            Eq_OwnerPhone: '联系方式不能为空',
            Eq_SpecCertNo: '特种设备制造许可证号不能为空',
            Eq_CertNo: '合格证号不能为空',
            Eq_ProducerCompanyId: '设备生产厂家不能为空',
            Eq_Producer: '设备生产厂家不能为空',
            Eq_MadeDate: '出厂日期不能为空',
            LimitedMonth : '设备使用年限不能为空'
        }
    });

    $("#Eq_Type").autocomplete({
        source: "/EquipmentModel/Suggestion",
        minLength: 2,
        select: function (event, ui) {
            $('#Eq_Type').val(ui.item.label);
            $('#LimitedYear').val(ui.item.Data);
            return false;
        },
        focus: function (event, ui) {
            $('#Eq_Type').val(ui.item.label);
            $('#LimitedYear').val(ui.item.Data);
            return false;
        }
    });

    $("#Eq_OwnerCompany").autocomplete({
        source: "/Company/Suggestion?type=owner",
        minLength: 1,
        select: function (event, ui) {
            $('#Eq_OwnerCompany').val(ui.item.label);
            $('#Eq_OwnerCompanyId').val(ui.item.Data.Id);
            $('#Eq_OwnerCompanyAddress').val(ui.item.Data.Address);
            $('#Eq_OwnerCompanyLegal').val(ui.item.Data.Legal);
            $('#Eq_OwnerCompanyPhone').val(ui.item.Data.Phone);
            $('#OwnerAddress').html(ui.item.Data.Address);
            return false;
        },
        focus: function (event, ui) {
            $('#Eq_OwnerCompany').val(ui.item.label);
            return false;
        }
    });

    $("#Eq_ProducerCompany").autocomplete({
        source: "/Company/Suggestion?type=prod",
        minLength: 1,
        select: function (event, ui) {
            $('#Eq_ProducerCompany').val(ui.item.label);
            $('#Eq_ProducerCompanyId').val(ui.item.Data.Id);
            return false;
        },
        focus: function (event, ui) {
            $('#Eq_ProducerCompany').val(ui.item.label);
            return false;
        }
    });
});